﻿// -------------------------------------------------------------------------------------------------------------------------------
// <copyright file="TestSubtractDenseSymmetricMatrixFactor.cs" company="Exul">
//     Copyright (c) Exul. All rights reserved.
// </copyright>
// <author>
//     Exul
// </author>
// -------------------------------------------------------------------------------------------------------------------------------

namespace ExulLibrary.Mathematics.LinearAlgebra.Sequential.Tests.DenseSymmetricMatrixTest.DoubleExtensions
{
    #region Usings

    using System;

    using ExulLibrary.Mathematics.LinearAlgebra.Sequential.DoubleExtensions;

    using NUnit.Framework;

    using Extensions = ExulLibrary.Mathematics.LinearAlgebra.Sequential.DoubleExtensions.DenseSymmetricMatrixExtensions;

    #endregion

    /// <summary>
    ///     Test suite for <see cref="Extensions.Subtract(DenseSymmetricMatrix{double},DenseSymmetricMatrix{double},double)"/>.
    /// </summary>
    [TestFixture]
    [Category("ExulLibrary.Mathematics.LinearAlgebra.Sequential.DoubleExtensions.DenseSymmetricMatrixExtensions")]
    public sealed class TestSubtractDenseSymmetricMatrixFactor
    {
        /// <summary>
        ///     Tests the method when minuend and subtrahend have the same size.
        /// </summary>
        [Test]
        public void WhenAugendAndAddendHaveTheSameSize()
        {
            // Arrange
            var subtrahendData = new double[] { 1, 2, 3 };
            var subtrahend = new DenseSymmetricMatrix<double>(subtrahendData);
            var minuendData = new double[] { 10, 20, 30 };
            var minuend = new DenseSymmetricMatrix<double>(minuendData);
            var expectedResult = new double[] { 5, 10, 15 };

            // Act
            minuend.Subtract(subtrahend, 5);

            // Assert
            Assert.That(minuend.Values, Is.EquivalentTo(expectedResult));
        }

        /// <summary>
        ///     Tests the method when subtrahend has less size than minuend.
        /// </summary>
        [Test]
        public void WhenSubtrahendHasLessSizeThanMinuend()
        {
            // Arrange
            var subtrahendData = new double[] { 1 };
            var subtrahend = new DenseSymmetricMatrix<double>(subtrahendData);
            var minuendData = new double[] { 10, 20, 30 };
            var minuend = new DenseSymmetricMatrix<double>(minuendData);
            var expectedResult = new double[] { 5, 20, 30 };

            // Act
            minuend.Subtract(subtrahend, 5);

            // Assert
            Assert.That(minuend.Values, Is.EquivalentTo(expectedResult));
        }

        /// <summary>
        ///     Tests the method when subtrahend has greater size than minuend.
        /// </summary>
        [Test]
        public void WhenSubtrahendHasGreaterSizeThanMinuend()
        {
            // Arrange
            var subtrahendData = new double[] { 1, 2, 3, 4, 5, 6 };
            var subtrahend = new DenseSymmetricMatrix<double>(subtrahendData);
            var minuendData = new double[] { 10, 20, 30 };
            var minuend = new DenseSymmetricMatrix<double>(minuendData);
            var expectedResult = new double[] { 5, 10, 15 };

            // Act
            minuend.Subtract(subtrahend, 5);

            // Assert
            Assert.That(minuend.Values, Is.EquivalentTo(expectedResult));
        }

#if SAFE

        /// <summary>
        ///     Tests the method when minuend is <see langword="null"/>.
        /// </summary>
        [Test]
        public void WhenMinuendIsNull()
        {
            // Arrange
            var subtrahend = new DenseSymmetricMatrix<double>(3);

            // Act and Assert
            Assert.That(
                () => DenseSymmetricMatrixExtensions.Subtract(null, subtrahend, 5),
                Throws.TypeOf<ArgumentNullException>().With.Property("ParamName").EqualTo("minuend"));
        }

        /// <summary>
        ///     Tests the method when subtrahend is <see langword="null"/>.
        /// </summary>
        [Test]
        public void WhenSubtrahendIsNull()
        {
            // Arrange
            var minuend = new DenseSymmetricMatrix<double>(3);

            // Act and Assert
            Assert.That(
                () => minuend.Subtract(null, 5),
                Throws.TypeOf<ArgumentNullException>().With.Property("ParamName").EqualTo("subtrahend"));
        }

#endif
    }
}